package cn.sh.yhk.config;


import org.redisson.spring.data.connection.RedissonConnectionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.connection.RedisConnectionFactory;

import java.time.Duration;


/**
 *
 * @Classname Yhk
 * @Description TODO
 * @Version 1.0.0
 * @Date 2024/10/15 12:29
 * @Created by y6522
 */
@Configuration
public class RedisCacheManager {


    @Bean
    public org.springframework.data.redis.cache.RedisCacheManager cacheManager(RedissonConnectionFactory redissonConnectionFactory) {
        RedisCacheConfiguration cacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
                .entryTtl(Duration.ofMinutes(10)) // 设置缓存过期时间
                .disableCachingNullValues(); // 禁止缓存空值

        return org.springframework.data.redis.cache.RedisCacheManager.builder(redissonConnectionFactory)
                .cacheDefaults(cacheConfiguration)
                .build();
    }


}
